{% extends "base.html" %}
{% load highlight %}

{% block title %}
Full-text search
{% endblock %}

{% block content %}
<style>
.highlighted {
    font-weight: bold;
}
</style>
<div class="row" id="results">
  <div class="large-12 columns">
    <h1>Search in links</h1>

    <form method="get" action="/search/" class="large-12 columns">
        <input id="id_q" name="q" type="text" value="{{ query }}">
        <input type="submit" value="Search" class="submit button small button">


        {% if query %}
            <script>
                window._gaq_page_name = 'FTSearchpage';
                _gaq.push(['_trackEvent', 'Search', window._gaq_page_name, "{{ query }}"]);
            </script>
            <h3>Results</h3>
            <p>Your query "{{ query }}" has returned {{ links.count }} result{{ links|pluralize }}</p>
            {% for result in links %}
                <h5><a href="{{ result.object.get_absolute_url }}">{{ result.title }}</a></h5>
                <p>
                    {% with result.content|striptags as stripped_text %}
                        {% highlight stripped_text with query %}
                    {% endwith %}
                </p>

            {% empty %}
                <p>No results found.</p>
            {% endfor %}

            {% if page.has_previous or page.has_next %}
                <div>
                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
                    |
                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
                </div>
            {% endif %}
        {% else %}
            <p>Hint: use double quotes to search for exact string.</p>
            <p>Use + operator to include something, - operator to exclude from search results.</p>
        {% endif %}
    </form>
  </div>
</div>
{% endblock %}
